#ifndef HWTIMER_H
#define HWTIMER_H

//#include <qglobal.h>

#define HIGH_SPEED    // 启用高速度低精度运算，将降低 calcTimerReload32 calcTimerReload64 两个算法的结束条件

#ifdef QT_VERSION
typedef qint32 rt_int32_t;
typedef quint32 rt_uint32_t;
typedef quint64 rt_uint64_t;
typedef quint8 rt_uint8_t;
#else
typedef signed   int rt_int32_t;
typedef unsigned int rt_uint32_t;
typedef unsigned long long rt_uint64_t;
typedef unsigned char rt_uint8_t;
#endif

typedef struct rt_hwtimerval
{
    rt_int32_t sec;      /* second */
    rt_int32_t usec;     /* microsecond */
} rt_hwtimerval_t;

/* Timer Feature Information */
struct rt_hwtimer_info
{
    rt_int32_t maxfreq;    /* the maximum count frequency timer support */
    rt_int32_t minfreq;    /* the minimum count frequency timer support */
    rt_uint8_t  cntmode;   /* count mode (inc/dec) */
};

typedef struct rt_hwtimer_device
{
    rt_uint32_t maxcnt;    /* counter maximum value */
    rt_int32_t freq;                /* counting frequency set by the user */
    float period_sec;
    rt_int32_t cycles;              /* how many times will generate a timeout event after overflow */
    rt_int32_t reload;              /* reload cycles(using in period mode) */
    rt_uint32_t counter;
} rt_hwtimer_t;

extern rt_uint32_t calcTimerReload1(rt_hwtimer_t *timer, rt_hwtimerval_t *tv);
extern rt_uint32_t calcTimerReload2(rt_hwtimer_t *timer, rt_hwtimerval_t *tv);

extern void presisionTest();
extern void speedTest();
extern void longTest();

#endif // HWTIMER_H
